<?php

/**
 * AccessPoint.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Amazon Shipping API.
 *
 * The Amazon Shipping API is designed to support outbound shipping use cases both for orders originating on Amazon-owned marketplaces as well as external channels/marketplaces. With these APIs, you can request shipping rates, create shipments, cancel shipments, and track shipments.
 *
 * The version of the OpenAPI document: v2
 * Contact: swa-api-core@amazon.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\shipping\v2;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * AccessPoint Class Doc Comment.
 *
 * @category Class
 *
 * @description Access point details
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class AccessPoint implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    public const ASSISTANCE_TYPE_STAFF_ASSISTED = 'STAFF_ASSISTED';
    public const ASSISTANCE_TYPE_SELF_ASSISTED = 'SELF_ASSISTED';

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'AccessPoint';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'access_point_id' => 'string',
        'name' => 'string',
        'timezone' => 'string',
        'type' => '\SpApi\Model\shipping\v2\AccessPointType',
        'accessibility_attributes' => '\SpApi\Model\shipping\v2\AccessibilityAttributes',
        'address' => '\SpApi\Model\shipping\v2\Address',
        'exception_operating_hours' => '\SpApi\Model\shipping\v2\ExceptionOperatingHours[]',
        'assistance_type' => 'string',
        'score' => 'string',
        'standard_operating_hours' => 'array<string,\SpApi\Model\shipping\v2\OperatingHours>'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'access_point_id' => null,
        'name' => null,
        'timezone' => null,
        'type' => null,
        'accessibility_attributes' => null,
        'address' => null,
        'exception_operating_hours' => null,
        'assistance_type' => null,
        'score' => null,
        'standard_operating_hours' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'access_point_id' => true,
        'name' => true,
        'timezone' => true,
        'type' => true,
        'accessibility_attributes' => true,
        'address' => true,
        'exception_operating_hours' => true,
        'assistance_type' => true,
        'score' => true,
        'standard_operating_hours' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'access_point_id' => 'accessPointId',
        'name' => 'name',
        'timezone' => 'timezone',
        'type' => 'type',
        'accessibility_attributes' => 'accessibilityAttributes',
        'address' => 'address',
        'exception_operating_hours' => 'exceptionOperatingHours',
        'assistance_type' => 'assistanceType',
        'score' => 'score',
        'standard_operating_hours' => 'standardOperatingHours',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'access_point_id' => 'setAccessPointId',
        'name' => 'setName',
        'timezone' => 'setTimezone',
        'type' => 'setType',
        'accessibility_attributes' => 'setAccessibilityAttributes',
        'address' => 'setAddress',
        'exception_operating_hours' => 'setExceptionOperatingHours',
        'assistance_type' => 'setAssistanceType',
        'score' => 'setScore',
        'standard_operating_hours' => 'setStandardOperatingHours',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'access_point_id' => 'getAccessPointId',
        'name' => 'getName',
        'timezone' => 'getTimezone',
        'type' => 'getType',
        'accessibility_attributes' => 'getAccessibilityAttributes',
        'address' => 'getAddress',
        'exception_operating_hours' => 'getExceptionOperatingHours',
        'assistance_type' => 'getAssistanceType',
        'score' => 'getScore',
        'standard_operating_hours' => 'getStandardOperatingHours',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('access_point_id', $data ?? [], null);
        $this->setIfExists('name', $data ?? [], null);
        $this->setIfExists('timezone', $data ?? [], null);
        $this->setIfExists('type', $data ?? [], null);
        $this->setIfExists('accessibility_attributes', $data ?? [], null);
        $this->setIfExists('address', $data ?? [], null);
        $this->setIfExists('exception_operating_hours', $data ?? [], null);
        $this->setIfExists('assistance_type', $data ?? [], null);
        $this->setIfExists('score', $data ?? [], null);
        $this->setIfExists('standard_operating_hours', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Gets allowable values of the enum.
     *
     * @return string[]
     */
    public function getAssistanceTypeAllowableValues(): array
    {
        return [
            self::ASSISTANCE_TYPE_STAFF_ASSISTED,
            self::ASSISTANCE_TYPE_SELF_ASSISTED,
        ];
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        $allowedValues = $this->getAssistanceTypeAllowableValues();
        if (!is_null($this->container['assistance_type']) && !in_array($this->container['assistance_type'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value '%s' for 'assistance_type', must be one of '%s'",
                $this->container['assistance_type'],
                implode("', '", $allowedValues)
            );
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets access_point_id.
     */
    public function getAccessPointId(): ?string
    {
        return $this->container['access_point_id'];
    }

    /**
     * Sets access_point_id.
     *
     * @param null|string $access_point_id Unique identifier for the access point
     */
    public function setAccessPointId(?string $access_point_id): self
    {
        if (is_null($access_point_id)) {
            array_push($this->openAPINullablesSetToNull, 'access_point_id');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('access_point_id', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['access_point_id'] = $access_point_id;

        return $this;
    }

    /**
     * Gets name.
     */
    public function getName(): ?string
    {
        return $this->container['name'];
    }

    /**
     * Sets name.
     *
     * @param null|string $name Name of entity (store/hub etc) where this access point is located
     */
    public function setName(?string $name): self
    {
        if (is_null($name)) {
            array_push($this->openAPINullablesSetToNull, 'name');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('name', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['name'] = $name;

        return $this;
    }

    /**
     * Gets timezone.
     */
    public function getTimezone(): ?string
    {
        return $this->container['timezone'];
    }

    /**
     * Sets timezone.
     *
     * @param null|string $timezone Timezone of access point
     */
    public function setTimezone(?string $timezone): self
    {
        if (is_null($timezone)) {
            array_push($this->openAPINullablesSetToNull, 'timezone');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('timezone', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['timezone'] = $timezone;

        return $this;
    }

    /**
     * Gets type.
     */
    public function getType(): ?string
    {
        return $this->container['type'];
    }

    /**
     * Sets type.
     *
     * @param null|string $type type
     */
    public function setType(?string $type): self
    {
        if (is_null($type)) {
            array_push($this->openAPINullablesSetToNull, 'type');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('type', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['type'] = $type;

        return $this;
    }

    /**
     * Gets accessibility_attributes.
     */
    public function getAccessibilityAttributes(): ?AccessibilityAttributes
    {
        return $this->container['accessibility_attributes'];
    }

    /**
     * Sets accessibility_attributes.
     *
     * @param null|AccessibilityAttributes $accessibility_attributes accessibility_attributes
     */
    public function setAccessibilityAttributes(?AccessibilityAttributes $accessibility_attributes): self
    {
        if (is_null($accessibility_attributes)) {
            array_push($this->openAPINullablesSetToNull, 'accessibility_attributes');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('accessibility_attributes', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['accessibility_attributes'] = $accessibility_attributes;

        return $this;
    }

    /**
     * Gets address.
     */
    public function getAddress(): ?Address
    {
        return $this->container['address'];
    }

    /**
     * Sets address.
     *
     * @param null|Address $address address
     */
    public function setAddress(?Address $address): self
    {
        if (is_null($address)) {
            array_push($this->openAPINullablesSetToNull, 'address');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('address', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['address'] = $address;

        return $this;
    }

    /**
     * Gets exception_operating_hours.
     */
    public function getExceptionOperatingHours(): ?array
    {
        return $this->container['exception_operating_hours'];
    }

    /**
     * Sets exception_operating_hours.
     *
     * @param null|array $exception_operating_hours Exception operating hours for Access Point
     */
    public function setExceptionOperatingHours(?array $exception_operating_hours): self
    {
        if (is_null($exception_operating_hours)) {
            array_push($this->openAPINullablesSetToNull, 'exception_operating_hours');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('exception_operating_hours', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['exception_operating_hours'] = $exception_operating_hours;

        return $this;
    }

    /**
     * Gets assistance_type.
     */
    public function getAssistanceType(): ?string
    {
        return $this->container['assistance_type'];
    }

    /**
     * Sets assistance_type.
     *
     * @param null|string $assistance_type Assistance type enum for Access point i.e. STAFF_ASSISTED or SELF_ASSISTED
     */
    public function setAssistanceType(?string $assistance_type): self
    {
        if (is_null($assistance_type)) {
            array_push($this->openAPINullablesSetToNull, 'assistance_type');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('assistance_type', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $allowedValues = $this->getAssistanceTypeAllowableValues();
        if (!is_null($assistance_type) && !in_array($assistance_type, $allowedValues, true)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value '%s' for 'assistance_type', must be one of '%s'",
                    $assistance_type,
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['assistance_type'] = $assistance_type;

        return $this;
    }

    /**
     * Gets score.
     */
    public function getScore(): ?string
    {
        return $this->container['score'];
    }

    /**
     * Sets score.
     *
     * @param null|string $score The score of access point, based on proximity to postal code and sorting preference. This can be used to sort access point results on shipper's end.
     */
    public function setScore(?string $score): self
    {
        if (is_null($score)) {
            array_push($this->openAPINullablesSetToNull, 'score');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('score', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['score'] = $score;

        return $this;
    }

    /**
     * Gets standard_operating_hours.
     *
     * @return null|array<string,OperatingHours>
     */
    public function getStandardOperatingHours(): ?array
    {
        return $this->container['standard_operating_hours'];
    }

    /**
     * Sets standard_operating_hours.
     *
     * @param null|array<string,OperatingHours> $standard_operating_hours Map of day of the week to operating hours of that day
     */
    public function setStandardOperatingHours(?array $standard_operating_hours): self
    {
        if (is_null($standard_operating_hours)) {
            array_push($this->openAPINullablesSetToNull, 'standard_operating_hours');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('standard_operating_hours', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['standard_operating_hours'] = $standard_operating_hours;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
